import { createRouter, createWebHistory } from 'vue-router'
import routes from './routes'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
})

router.beforeEach((to, from, next) => {
  // if (to.meta.ignoreAuth) {
  //   return next()
  // }
  const token = CookieHelper.get()
  // if (!token && to.path !== '/sign-in') {
  //   return next(`/sign-in?redirect=${from.fullPath}`)
  // }
  if (token && to.path === '/sign-in') {
    return next('/')
  }
  return next()
})

export default router
